package com.mofang.ticketing.common.core.enums.base;

import com.mofang.ticketing.common.core.enums.EnumVO;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @author LGC
 * @date 2022/10/9 15:24
 */
@Getter
@AllArgsConstructor
public enum GenderEnum {
    /**
     * 性别枚举
     */
    MALE(1, "男"),
    FEMALE(2, "女"),
    ;
    private final Integer key;
    private final String value;

    public static String getValueByKey(int key) {
        Optional<GenderEnum> optional = Arrays.stream(GenderEnum.values())
                .filter(v -> v.getKey() == key).findAny();
        return optional.map(GenderEnum::getValue).orElse(null);
    }

    public static List<EnumVO> getKeyValueList() {
        return Arrays.stream(GenderEnum.values()).map(s ->
                new EnumVO(s.getKey(), s.getValue())).collect(Collectors.toList());
    }
}
